﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="view_working.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.Staff.view_working" %>

<%@ Import Namespace="DataAccess" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<body>
    <table class="w3-table w3-white w3-bordered w3-centered w3-striped">
        <thead>
            <tr class="w3-teal">
                <th>Giáo viên</th>
                <th>Giờ làm</th>
                <%
                    DateTime temp = DateTime.Parse(this.week_start.ToString());
                %>
                <th>Thứ 2 (<%=temp.Day %>/<%=temp.Month %>)</th>
                <%for (int i = 1; i < 7; i++)
                  {%>

                <%
                      if (temp.AddDays(i).DayOfWeek == DayOfWeek.Sunday)
                      {%>
                <th>Chủ Nhật (<%=temp.AddDays(i).Day %>/<%=temp.AddDays(i).Month %>)</th>
                <%}
                      else
                      {
                          int day = (int)temp.AddDays(i).DayOfWeek;%>
                <th>Thứ <%=day+=1 %> (<%=temp.AddDays(i).Day %>/<%=temp.AddDays(i).Month %>)</th>
                <%}
                  }%>
            </tr>
        </thead>
        <%
            var get_staff = new TblManagerController().FetchAll().Where(x => x.Role == int.Parse(Session["admin_level"].ToString()) && x.Active == true);
            foreach (TblManager staff in get_staff)
            {
                var get_work = new TblWorkingController().FetchAll().Where(x => x.Manager == staff.ManagerId && x.Week == this.id).ToList();
                string time = "&nbsp;", mon = "&nbsp;", tue = "&nbsp;", thu = "&nbsp;", wed = "&nbsp;", fri = "&nbsp;", sat = "&nbsp;", sun = "&nbsp;";
                int row_id = 0;
                if (get_work.Count > 0)
                {
                    if (!string.IsNullOrEmpty(get_work[0].Time))
                        time = get_work[0].Time;
                    if (!string.IsNullOrEmpty(get_work[0].Monday))
                        mon = get_work[0].Monday;
                    if (!string.IsNullOrEmpty(get_work[0].Tuesday))
                        tue = get_work[0].Tuesday;
                    if (!string.IsNullOrEmpty(get_work[0].Wednesday))
                        wed = get_work[0].Wednesday;
                    if (!string.IsNullOrEmpty(get_work[0].Friday))
                        fri = get_work[0].Friday;
                    if (!string.IsNullOrEmpty(get_work[0].Thursday))
                        thu = get_work[0].Thursday;
                    if (!string.IsNullOrEmpty(get_work[0].Saturday))
                        sat = get_work[0].Saturday;
                    if (!string.IsNullOrEmpty(get_work[0].Sunday))
                        sun = get_work[0].Sunday;
                    if (!string.IsNullOrEmpty(get_work[0].Id.ToString()))
                        row_id = get_work[0].Id;
                }
        %>
        <tr class="row_work">
            <td class="w3-hide row_id"><%=row_id %></td>
            <td class="w3-hide manager_id"><%=staff.ManagerId %></td>
            <td rowspan="6" class="w3-border-right">
                <img src="../Content/avatar/<%=staff.Avatar%>" class="staff-work-img" /><br />
                <label class="w3-row"><%=staff.FullName %></label></td>
            <td class="work_time work">
                <input class='edited' autofocus='autofocus' type='text' value='<%=time %>' /></td>
            <td class="work_mon work">
                <input class='edited' autofocus='autofocus' type='text' value='<%=mon %>' /></td>
            <td class="work_tue work">
                <input class='edited' autofocus='autofocus' type='text' value='<%=tue %>' /></td>
            <td class="work_wed work">
                <input class='edited' autofocus='autofocus' type='text' value='<%=wed %>' /></td>
            <td class="work_thu work">
                <input class='edited' autofocus='autofocus' type='text' value='<%=thu %>' /></td>
            <td class="work_fri work">
                <input class='edited' autofocus='autofocus' type='text' value='<%=fri %>' /></td>
            <td class="work_sat work">
                <input class='edited' autofocus='autofocus' type='text' value='<%=sat %>' /></td>
            <td class="work_sun work">
                <input class='edited' autofocus='autofocus' type='text' value='<%=sun %>' /></td>
        </tr>

        <%
                for (int i = 1; i < 6; i++)
                {
                    string time1 = "&nbsp;", mon1 = "&nbsp;", tue1 = "&nbsp;", thu1 = "&nbsp;", wed1 = "&nbsp;", fri1 = "&nbsp;", sat1 = "&nbsp;", sun1 = "&nbsp;";
                    int row_id1 = 0;
                    if (get_work.Count > i)
                    {
                        if (!string.IsNullOrEmpty(get_work[i].Time))
                            time1 = get_work[i].Time;
                        if (!string.IsNullOrEmpty(get_work[i].Monday))
                            mon1 = get_work[i].Monday;
                        if (!string.IsNullOrEmpty(get_work[i].Tuesday))
                            tue1 = get_work[i].Tuesday;
                        if (!string.IsNullOrEmpty(get_work[i].Wednesday))
                            wed1 = get_work[i].Wednesday;
                        if (!string.IsNullOrEmpty(get_work[i].Friday))
                            fri1 = get_work[i].Friday;
                        if (!string.IsNullOrEmpty(get_work[i].Thursday))
                            thu1 = get_work[i].Thursday;
                        if (!string.IsNullOrEmpty(get_work[i].Saturday))
                            sat1 = get_work[i].Saturday;
                        if (!string.IsNullOrEmpty(get_work[i].Sunday))
                            sun1 = get_work[i].Sunday;
                        if (!string.IsNullOrEmpty(get_work[i].Id.ToString()))
                            row_id1 = get_work[i].Id;
                    }
        %>
        <tr class="row_work">
            <td class="w3-hide manager_id"><%=staff.ManagerId %></td>
            <td class="w3-hide row_id"><%=row_id1 %></td>
            <td class="work_time work">
                <input class='edited' autofocus='autofocus' type='text' value='<%=time1 %>' /></td>
            <td class="work_mon work">
                <input class='edited' autofocus='autofocus' type='text' value='<%=mon1 %>' /></td>
            <td class="work_tue work">
                <input class='edited' autofocus='autofocus' type='text' value='<%=tue1 %>' /></td>
            <td class="work_wed work">
                <input class='edited' autofocus='autofocus' type='text' value='<%=wed1 %>' /></td>
            <td class="work_thu work">
                <input class='edited' autofocus='autofocus' type='text' value='<%=thu1 %>' /></td>
            <td class="work_fri work">
                <input class='edited' autofocus='autofocus' type='text' value='<%=fri1 %>' /></td>
            <td class="work_sat work">
                <input class='edited' autofocus='autofocus' type='text' value='<%=sat1 %>' /></td>
            <td class="work_sun work">
                <input class='edited' autofocus='autofocus' type='text' value='<%=sun1 %>' /></td>
        </tr>
        <%}%>

        <%} %>
    </table>
</body>
</html>
